package controlGraph;

/**
 * @author Administrator
 * The structure of the AbstractInt value of each variable
 */
public class AbstractInt {
	
	private boolean pos = false;
	private boolean zero = false;
	private boolean neg = false;
	
	public AbstractInt(){
		
	}
	
	public AbstractInt(AbstractInt In){
		if(In.getPos())
			this.setPos();
		if(In.getZero())
			this.setZero();
		if(In.getNeg())
			this.setNeg();
	}
	
	public AbstractInt(int num){
		if(num > 0){
			pos = true;
		}
		else if(num ==0 ){
			zero = true;
		}
		else if(num < 0){
			neg =true;
		}		
	}
	
	public void setPos(){
		this.pos = true;
	}
	
	public boolean getPos(){
		return this.pos;
	}


	public void setZero(){
		this.zero = true;
	}
	
	public boolean getZero(){
		return this.zero;
	}


	public void setNeg(){
		this.neg = true;
	}
	
	public boolean getNeg(){
		return this.neg;
	}
	
	public void setAll(){
		this.setPos();
		this.setZero();
		this.setNeg();
	}
	
	public AbstractInt add(AbstractInt a){
		
		AbstractInt ret = new AbstractInt();
		if(this.getPos() || a.getPos() )
		{
			ret.setPos();
		}
		
		if(this.getNeg() || a.getNeg())
		{
			ret.setNeg();
		}
		
		if((this.getNeg()^a.getPos()) || (this.getPos()^a.getNeg())){
			ret.setAll();
		}
		
		if(this.getZero()){
			if(a.getPos())
				ret.setPos();
			if(a.getZero())
				ret.setZero();
			if(a.getNeg())
				ret.setZero();
		}
		
		if(a.getZero()){
			if(this.getPos())
				ret.setPos();
			if(this.getZero())
				ret.setZero();
			if(this.getNeg())
				ret.setZero();
		}
		
		return ret;
	}
	
	public AbstractInt sub(AbstractInt a){
		
		AbstractInt ret = new AbstractInt();
		
		//First Argument is Positive
		if(this.getPos()){
			if(a.getPos() || a.getNeg()){
				ret.setAll();
				return ret;
			}
			if(a.getZero()){
				ret = new AbstractInt(this);
				return ret;
			}			
		}
		
		//First Argument is Negative
		if(this.getNeg()){
			if(a.getNeg() || a.getPos()){
				ret.setAll();
				return ret;
			}
			if(a.getZero()){
				ret = new AbstractInt(this);
				return ret;
			}				
		}
		
		//First Argument is Zero
		if(this.getZero()){
			if(a.getZero())
				ret.setZero();
			if(a.getPos())
				ret.setNeg();
			if(a.getNeg())
				ret.setPos();
		}
		
		return ret;
	}
}
